package com.ruoyi.process.controller;

import java.util.List;

import com.ruoyi.main.service.IMainUnitesService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.process.domain.ProcessBucket;
import com.ruoyi.process.service.IProcessBucketService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 装箱管理Controller
 * 
 * @author chao
 * @date 2024-07-25
 */
@Controller
@RequestMapping("/process/bucket")
public class ProcessBucketController extends BaseController
{
    private String prefix = "process/bucket";

    @Autowired
    private IProcessBucketService processBucketService;

    @Autowired
    private IMainUnitesService mainUnitesService;

    @RequiresPermissions("process:bucket:view")
    @GetMapping()
    public String bucket()
    {
        return prefix + "/bucket";
    }

    /**
     * 查询装箱管理列表
     */
    @RequiresPermissions("process:bucket:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ProcessBucket processBucket)
    {
        startPage();
        List<ProcessBucket> list = processBucketService.selectProcessBucketList(processBucket);
        return getDataTable(list);
    }

    /**
     * 导出装箱管理列表
     */
    @RequiresPermissions("process:bucket:export")
    @Log(title = "装箱管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ProcessBucket processBucket)
    {
        List<ProcessBucket> list = processBucketService.selectProcessBucketList(processBucket);
        ExcelUtil<ProcessBucket> util = new ExcelUtil<ProcessBucket>(ProcessBucket.class);
        return util.exportExcel(list, "装箱管理数据");
    }

    /**
     * 新增装箱管理
     */
    @GetMapping("/add")
    public String add(Model model)
    {
        model.addAttribute("uniteNames",mainUnitesService.getAllNormalNames());
        return prefix + "/add";
    }

    /**
     * 新增保存装箱管理
     */
    @RequiresPermissions("process:bucket:add")
    @Log(title = "装箱管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ProcessBucket processBucket)
    {
        return toAjax(processBucketService.insertProcessBucket(processBucket));
    }

    /**
     * 修改装箱管理
     */
    @RequiresPermissions("process:bucket:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        ProcessBucket processBucket = processBucketService.selectProcessBucketById(id);
        mmap.put("processBucket", processBucket);
        mmap.put("uniteNames",mainUnitesService.getAllNormalNames());
        return prefix + "/edit";
    }

    /**
     * 修改保存装箱管理
     */
    @RequiresPermissions("process:bucket:edit")
    @Log(title = "装箱管理", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ProcessBucket processBucket,Model model)
    {
        model.addAttribute("uniteNames",mainUnitesService.getAllNormalNames());
        return toAjax(processBucketService.updateProcessBucket(processBucket));
    }

    /**
     * 删除装箱管理
     */
    @RequiresPermissions("process:bucket:remove")
    @Log(title = "装箱管理", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(processBucketService.deleteProcessBucketByIds(ids));
    }
}
